package com.jiot.controller.user;

import com.zg.cloud.BaseResponse;
import com.zg.cloud.annotation.TokenCheck;
import com.zg.cloud.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import req.user.SendAppRegisterCodeReq;
import req.user.*;
import resp.user.AppUserInfoResp;
import resp.user.AppUserLoginResp;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author liling
 * @date 2020/10/10 16:25
 * @description 用户模块
 **/
@RestController
@RequestMapping("/user/user")
@Api(value = "用户模块")
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping("/app/login")
    @ApiOperation(value = "app用户登录", notes = "user")
    public BaseResponse appLogin(@RequestBody @Valid AppUserLoginReq appUserLoginReq) {
        AppUserLoginResp resp = userService.appUserLogin(appUserLoginReq);
        BaseResponse baseResponse = new BaseResponse();
        baseResponse.setData(resp);
        return baseResponse;
    }

    @PostMapping("/app/register")
    @ApiOperation(value = "app用户注册", notes = "user")
    public BaseResponse appRegister(@RequestBody @Valid AppUserRegisterReq appUserRegisterReq) {
        userService.register(appUserRegisterReq);
        return new BaseResponse();
    }

    @PostMapping("/app/logout")
    @ApiOperation(value = "app用户注销", notes = "user")
    @TokenCheck
    public BaseResponse logout() {
        userService.logout();
        return new BaseResponse();
    }

    @PostMapping("/app/reset/password")
    @ApiOperation(value = "app用户重置密码", notes = "user")
    @TokenCheck
    public BaseResponse resetPassword(@RequestBody @Valid AppUserResetPasswordReq appUserResetPasswordReq) {
        userService.resetPassword(appUserResetPasswordReq);
        return new BaseResponse();
    }

    @PostMapping("/app/forget/password")
    @ApiOperation(value = "app忘记密码", notes = "user")
    public BaseResponse forgetPassword(@RequestBody @Valid AppUserForgetPasswordReq appUserForgetPasswordReq) {
        userService.forgetPassword(appUserForgetPasswordReq);
        return new BaseResponse();
    }

    @PostMapping("/app/user/info")
    @TokenCheck
    @ApiOperation(value = "app用户获取个人资料", notes = "user")
    public BaseResponse appUserInfo() {
        AppUserInfoResp appUserInfoResp = userService.getAppUserInfo();
        return new BaseResponse(appUserInfoResp);
    }

    @PostMapping("/app/update/info")
    @TokenCheck
    @ApiOperation(value = "app用户修改用户信息", notes = "user")
    public BaseResponse appUpdateInfo(@RequestBody @Valid AppUserUpdateInfoReq appUserUpdateInfoReq) {
        userService.appUpdateInfo(appUserUpdateInfoReq);
        return new BaseResponse();
    }

    @PostMapping("/app/register/code")
    @ApiOperation(value = "app用户发送注册验证码", notes = "user")
    public BaseResponse appRegisterCode(@RequestBody @Valid SendAppRegisterCodeReq sendAppRegisterCodeReq) {
        userService.sendAppRegisterCode(sendAppRegisterCodeReq);
        return new BaseResponse();
    }

    @PostMapping("/app/forget/code")
    @ApiOperation(value = "app用户忘记密码发送短信验证码", notes = "user")
    public BaseResponse appForgetPassword(@RequestBody @Valid SendAppForgetPasswordCodeReq sendAppForgetPasswordCodeReq) {
        userService.sendAppForgetPasswordCode(sendAppForgetPasswordCodeReq);
        return new BaseResponse();
    }

    @PostMapping("/send/update/phone/code")
    @TokenCheck
    @ApiOperation(value = "app用户修改手机号发送短信验证码", notes = "user")
    public BaseResponse appSendUpdatePhone(@RequestBody @Valid SendAppUpdatePhoneCodeReq sendAppUpdatePhoneCodeReq) {
        userService.appSendUpdatePhone(sendAppUpdatePhoneCodeReq);
        return new BaseResponse();
    }

    @PostMapping("/app/update/phone")
    @TokenCheck
    @ApiOperation(value = "app用户修改手机号", notes = "user")
    public BaseResponse appUpdatePhone(@RequestBody @Valid AppUpdatePhoneReq appUpdatePhoneReq) {
        userService.appUpdatePhone(appUpdatePhoneReq);
        return new BaseResponse();
    }

    @PostMapping("/app/wx/user/login")
    @ApiOperation(value = "app微信登录", notes = "user")
    public BaseResponse appWxUserLogin(@RequestBody @Valid AppWxUserLoginReq appWxUserLoginReq) {
        BaseResponse baseResponse = new BaseResponse();
        baseResponse.setData(userService.appWxUserLogin(appWxUserLoginReq));
        return baseResponse;
    }

    @PostMapping("/mini/program/user/login")
    @ApiOperation(value = "小程序微信登录", notes = "user")
    public BaseResponse miniProgramUserLogin(@RequestBody @Valid MiniProgramUserLoginRep miniProgramUserLoginRep) {
        BaseResponse baseResponse = new BaseResponse();
        baseResponse.setData(userService.miniProgramUserLogin(miniProgramUserLoginRep));
        return baseResponse;
    }

    @PostMapping("/app/perfect/info")
    @TokenCheck
    @ApiOperation(value = "app用户完善个人资料", notes = "user")
    public BaseResponse perfectInfo(@RequestBody @Valid AppPerfectInfoReq appPerfectInfoReq) {
        userService.perfectInfo(appPerfectInfoReq);
        return new BaseResponse();
    }

    @PostMapping("/send/perfect/code")
    @TokenCheck
    @ApiOperation(value = "app用户发送完善个人资料验证码", notes = "user")
    public BaseResponse sendPerfectCode(@RequestBody @Valid SendAppPerfectInfoCodeReq sendAppPerfectInfoCodeReq) {
        return new BaseResponse(userService.sendPerfectCode(sendAppPerfectInfoCodeReq));
    }

    @PostMapping("/verify/mobile/phone/number")
    @TokenCheck
    @ApiOperation(value = "验证手机号是否注册存在", notes = "user")
    public BaseResponse verifyMobilePhoneNumber(@RequestBody @Valid VerifyMobilePhoneNumberReq verifyMobilePhoneNumberReq) {
        return new BaseResponse(userService.verifyMobilePhoneNumber(verifyMobilePhoneNumberReq));
    }

    @PostMapping("/report/info")
    @TokenCheck
    @ApiOperation(value = "周报月报用户信息", notes = "user")
    public BaseResponse reportInfo() {
        return new BaseResponse(userService.reportInfo());
    }

    @PostMapping("/get/user/by/area")
    @TokenCheck
    @ApiOperation(value = "获取当前登录用户下所有用户", notes = "user")
    public BaseResponse getUserByArea() {
        return new BaseResponse(userService.getUserByArea());
    }

    @PostMapping("/user/info/list")
    @TokenCheck
    @ApiOperation(value = "获取用户信息列表", notes = "user")
    public BaseResponse userInfoList(@RequestBody @Valid GetUserInfoListReq getUserInfoListReq) {
        return new BaseResponse(userService.userInfoList(getUserInfoListReq));
    }

    @PostMapping("/by/id")
    @TokenCheck
    @ApiOperation(value = "根据id查询", notes = "user", hidden = true)
    public BaseResponse getById(@RequestBody GetUserByIdReq getUserByIdReq) {
        AppUserInfoResp appUserInfoResp = userService.getById(getUserByIdReq);
        return new BaseResponse(appUserInfoResp);
    }

    @PostMapping("/list/by/ids")
    @TokenCheck
    @ApiOperation(value = "根据id查询", notes = "user", hidden = true)
    public BaseResponse getListByIds(@RequestBody GetUserListByIdsReq getUserListByIdsReq) {
        return new BaseResponse(userService.getListByIds(getUserListByIdsReq));
    }

    @PostMapping("/functional/area/list")
    @ApiOperation(value = "查询职能用户区域信息列表", notes = "user", hidden = true)
    public BaseResponse functionalAreaList() {
        return new BaseResponse(userService.functionalAreaList());
    }
}
